package com.bluebench.bigul.domain;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;


public class EnumInvocation extends Invocation{
	
	public EnumInvocation(){
		this.setElementType(ElementType.INVOCATION);
	}
	
	
	@Override
	public Object invoke() throws SecurityException, IllegalArgumentException,
			ClassNotFoundException, NoSuchMethodException,
			IllegalAccessException, InvocationTargetException,
			InstantiationException, NoSuchFieldException {
		// TODO Auto-generated method stub
		/*String className = getClassName();
		Object returnVal=null;
		Class<?> clazz = Class.forName(className);
		if(clazz.isEnum()){
			Field f = clazz.getField(getField());
			returnVal = f.get(null);
		}*/
		
		Object returnVal=null;
		String field = getField();
		if(field.contains(".")){
			String[] parts = field.split("\\.");
			String className = Types.getType(parts[0]).getClassName();
			String fieldName = parts[1];
			try {
				
				Class<?> clazz = Class.forName(className);
				Field f = clazz.getField(fieldName);				
				if(clazz.isEnum()){
					returnVal = f.get(null);
				}else{
					//TODO : Throw Appropriate Exception about bad Invocation Configuration.
				}
				
			} catch (IllegalAccessException e1) {					
				e1.printStackTrace();
			} catch (ClassNotFoundException e1) {					
				e1.printStackTrace();
			} catch (SecurityException e1) {					
				e1.printStackTrace();
			} catch (NoSuchFieldException e1) {					
				e1.printStackTrace();
			} 
		}
		
		return returnVal;
	}

	

}
